<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
	<form id="widgetSnaphsotSbumit" name="dataForm" method="post"
		action="{{ctx}}/mam/widgetSnapshot/add" enctype="multipart/form-data">
		<div class="text-right pad-st-b5">
			<input class="In" type="hidden" id="versionId" name="versionId"
				value="{{versionId}}" />
			<table class="text-center">
				<tr>
					<td class="bd_sr" width="10%"></td>
					<td class="bd_sr"><div id="snaphotUploadContainer"></div></td>
				</tr>
			</table>
		</div>
	</form>
</body>
</html>
<script type="text/javascript">
	var popover = function(inputId, content) {
		var options = {
			placement : "bottom",
			content : content
		};
		$('#' + inputId).attr("data-toggle", "popover");
		$('#' + inputId).popover(options);
		$('#' + inputId).popover('show');
	}
	$(function() {
		var uploader = buildPlupload({
			id : "snaphotUploadContainer",
			elmName : "snapshot",
            filters : [{title : "图片", extensions : "png"}],
			targetUrl : "{{ctx}}/mam/attachment/upload",
			defaultVal : "",
			btnName : "上传快照"
		});

		uploader.bind('FileUploaded', function(up, files, info) {
			var obj = eval("(" + info.response + ")");
			var id = obj.id;
			var tel = /.png$/;
			var value = jQuery("#snaphotUploadContainerName").val();
			if (value != null && value != "") {
				if (!tel.test(value)) {
					popover("snaphotUploadContainerBtn", "请上传png格式图片");
					$('#snaphotUploadContainerInput').val("");
					return false;
				}
			}

		});
	});

	function widgetSnaphsotSbumit() {
		var value = $('#snaphotUploadContainerInput').val();
		if (value == "") {
			popover("snaphotUploadContainerBtn", "请上传png格式图片");
			return false;
		}
		var data = $('#widgetSnaphsotSbumit').serialize();
		$.ajax({
			async : true,
			type : "POST",
			url : "{{ctx}}/mam/widgetSnapshot/add",
			data : data,
			dataType : 'json',
			success : function(result, textStatus) {
				if (result.result == "success") {
					window.location.reload();
				} else {
					bootbox.alert("添加失败，请稍后再试！");
				}
			},
			error : function(data, status, e) {
				bootbox.alert("系统繁忙，请稍后再试！");
			}
		});

	}
</script>
